package org.example.game.history;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/25 22:40
 */
public class Solution100309 {

    public static void main(String[] args) {
        Solution100309 solution100309 = new Solution100309();
        System.out.println(solution100309.duplicateNumbersXOR(new int[]{1,2,2,1}));
    }


    public int duplicateNumbersXOR(int[] nums) {
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();

        for(int n : nums){
            if(list1.contains(n)){
                list2.add(n);
            }else {
                list1.add(n);
            }
        }

        if(list2.size() == 0){
            return 0;
        }

        if(list2.size() == 1){
            return list2.get(0);
        }

        int res = list2.get(0);
        for(int i = 1;i<list2.size();i++){
            res = res ^ list2.get(i);
        }
        return res;
    }
}
